/*action create by pionner code builder*/

package com.pioneer.app.sms.log;

import java.util.Date;
import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.Query;
import org.hibernate.Transaction;

import com.app.util.DateTimeUtil;

import config.BaseHibernateDAO;

public class SmsSendLogDAO extends BaseHibernateDAO {
	private static final Log log = LogFactory.getLog(SmsSendLog.class);
	public SmsSendLog findBySendLogId(java.lang.Long id){
		log.debug("getting SmsSendLog instance with id: " + id);
		try {
			SmsSendLog instance =(SmsSendLog)getSession().get("com.pioneer.app.sms.log.SmsSendLog",id);
			return instance;
		}catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}
	public void delete(SmsSendLog persistentInstance){
		log.debug("deletting SmsSendLog persistentInstance  ");
		try {
			getSession().delete(persistentInstance);
			log.debug("delete successful");
		}catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}
	public void add(SmsSendLog persistentInstance){
		log.debug("deletting SmsSendLog persistentInstance  ");
		try {
			getSession().save(persistentInstance);
			log.debug("add successful");
		}catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}
	public void update(SmsSendLog persistentInstance){
		log.debug("deletting SmsSendLog persistentInstance  ");
		try {
			getSession().update(persistentInstance);
			log.debug("update successful");
		}catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}
	public List findByCondition(String condition){
		log.debug("finding by condition "+condition);
		try {

			String queryString =null;
			if(null!=condition){
				queryString = "from SmsSendLog where "+condition+" order by sendLogId desc";
			}else{queryString = "from SmsSendLog order by sendLogId desc";
			}

			Query queryObject = getSession().createQuery(queryString);
			queryObject.setMaxResults(500);
			return queryObject.list();
		}catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}
	public void deleteObjs(java.lang.Long[]ids){
		log.debug("deleting by objects ");
		Transaction tx=this.getSession().beginTransaction();
		try {
			if(null!=ids){
				SmsSendLog obj=null;
				java.lang.Long id=null;
				for(int i=0;i<ids.length;i++){
					id=ids[i];
					obj=this.findBySendLogId(id);
//					obj.setSendLogId(isd);
					this.delete(obj);
				}
				tx.commit();
			}
		}catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}
	
	public static void main(String[]args){
		Date date=DateTimeUtil.parse("2008-12-22", "yyyy-MM-dd");
		String cond="sendTime >=  '2008-12-22'";
		SmsSendLogDAO dao=new SmsSendLogDAO();
		List list=dao.findByCondition(cond);
		System.out.println(list.size());
	}
}
